package com.graduate.work.graduatework.service;

import com.graduate.work.graduatework.entity.AirTicketDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author: cuibingqi.
 * @date: 17/5/1 下午10:47.
 * @descripe: 低价搜索服务
 */
@Service
public class SearchService {

    @Autowired
    private ParseAirTicketDataService parseAirTicketDataService;

    /**
     * 单程搜索服务
     * @param DCity1
     * @param ACity1
     * @param DDate1
     */
    public List<AirTicketDetail> OWSearch(String DCity1, String ACity1, String DDate1){
        List<AirTicketDetail> quna = parseAirTicketDataService.parseQuNAirTicket(DCity1,ACity1,DDate1);
        List<AirTicketDetail> meit = parseAirTicketDataService.parseMTAirTicket(DCity1,ACity1,DDate1);
        List<AirTicketDetail> feiz = parseAirTicketDataService.parseFeZAirTicket(DCity1,ACity1,DDate1);

        List<AirTicketDetail> list = new ArrayList<AirTicketDetail>();
        list.addAll(quna);
        list.addAll(meit);
        list.addAll(feiz);

        //按照价格排序
        Collections.sort(list, (param1,param2)->{
            if(param1.getPrice() > param2.getPrice()){
                return 1;
            }
            if(param1.getPrice() == param2.getPrice()){
                return 0;
            }
            return -1;
        });

        System.out.println("biubiubiu"+list);
        return list;
    }

    /**
     * 往返搜索
     */
    public void RTSearch(){

    }
}
